using DbType = System.Data.DbType;
namespace SB2.Core;

/// <summary>
/// sql 参数
/// </summary>
public class SugarParameterDto
{
    public string Name { get; set; }
    public object Value { get; set; }
    public DbType Type { get; set; }

    public SugarParameterDto(string name, object value, DbType type)
    {
        this.Name = name;
        this.Value = value;
        this.Type = type;
    }
    public object GetVaule()
    {
        // Console.WriteLine(this.Value);
        // Console.WriteLine(Type);
        // Console.WriteLine(this.Value != null && typeof(System.Text.Json.JsonElement) == this.Value.GetType());

        if (this.Value != null && typeof(System.Text.Json.JsonElement) == this.Value.GetType())
        {
            var data = Value + "";
            switch (Type)
            {
                case DbType.String:
                    this.Value = data;
                    break;
                case DbType.Int64:
                    this.Value = Int64.Parse(data);
                    break;
                case DbType.Int32:
                    this.Value = Int32.Parse(data);
                    break;
                case DbType.Int16:
                    this.Value = Int16.Parse(data);
                    break;
                case DbType.Date:
                case DbType.DateTime:
                case DbType.DateTime2:
                    this.Value = DateTime.Parse(data);
                    break;
            }

        }
        return this.Value;
    }
}